unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, RzPanel, RzSplit,FormEx_View, StdCtrls, RzLstBox,
  RzButton,SyncObjs;

type
  TForm1 = class(TFormExView)
    RzSplitter1: TRzSplitter;
    RzSplitter2: TRzSplitter;
    RzGroupBox1: TRzGroupBox;
    RzGroupBox2: TRzGroupBox;
    RzGroupBox3: TRzGroupBox;
    List_1: TRzListBox;
    List_2: TRzListBox;
    List_3: TRzListBox;
    Tool_1: TRzToolbar;
    Btnx_1: TRzToolButton;
    Btnx_2: TRzToolButton;
    Btnx_3: TRzToolButton;
    Btnx_4: TRzToolButton;
    procedure Btnx_4Click(Sender: TObject);
    procedure Btnx_1Click(Sender: TObject);
    procedure Btnx_2Click(Sender: TObject);
    procedure Btnx_3Click(Sender: TObject);
  private
  protected
    procedure SetInitialize;override;
    procedure SetCommParams;override;
    procedure SetGridParams;override;
    procedure SetComboItems;override;
    procedure TryFreeAndNil;override;
  public
  end;

var
  Form1: TForm1;
var
  CS: TRTLCriticalSection;
  BS: TCriticalSection;

implementation

{$R *.dfm}

{ TForm1 }
function MyThreadFun1(p: Pointer): DWORD; stdcall;
var
  I: Integer;
begin
  for I := 0 to 99 do
  begin
    Form1.List_1.Items.Add(IntToStr(I));
  end;
  Result := 0;
end;

function MyThreadFun2(p: Pointer): DWORD; stdcall;
var
  I: Integer;
begin
  EnterCriticalSection(CS);
  for I := 0 to 99 do
  begin
    Form1.List_2.Items.Add(IntToStr(I));
  end;
  LeaveCriticalSection(CS);
  Result := 0;
end;

function MyThreadFun3(p: Pointer): DWORD; stdcall;
var
  I: Integer;
begin
  BS.Enter;
  for I := 0 to 99 do
  begin
    Form1.List_3.Items.Add(IntToStr(I));
  end;
  BS.Leave;
  Result := 0;
end;

procedure TForm1.SetComboItems;
begin
  inherited;

end;

procedure TForm1.SetCommParams;
begin
  inherited;
  RzSplitter1.Percent:=30;
  RzSplitter2.Percent:=50;
end;

procedure TForm1.SetGridParams;
begin
  inherited;

end;

procedure TForm1.SetInitialize;
begin
  inherited;
  InitializeCriticalSection(CS);
  BS:=TCriticalSection.Create;
end;

procedure TForm1.TryFreeAndNil;
begin
  inherited;
  DeleteCriticalSection(CS);
  BS.Free;
end;

procedure TForm1.Btnx_4Click(Sender: TObject);
begin
  Application.Terminate;
end;

procedure TForm1.Btnx_1Click(Sender: TObject);
var
  ID: DWORD;
begin
  CreateThread(nil, 0, @MyThreadFun1, nil, 0, ID);
  CreateThread(nil, 0, @MyThreadFun1, nil, 0, ID);
  CreateThread(nil, 0, @MyThreadFun1, nil, 0, ID);
end;


procedure TForm1.Btnx_2Click(Sender: TObject);
var
  ID: DWORD;
begin
  CreateThread(nil, 0, @MyThreadFun2, nil, 0, ID);
  CreateThread(nil, 0, @MyThreadFun2, nil, 0, ID);
  CreateThread(nil, 0, @MyThreadFun2, nil, 0, ID);
end;

procedure TForm1.Btnx_3Click(Sender: TObject);
var
  ID: DWORD;
begin
  CreateThread(nil, 0, @MyThreadFun3, nil, 0, ID);
  CreateThread(nil, 0, @MyThreadFun3, nil, 0, ID);
  CreateThread(nil, 0, @MyThreadFun3, nil, 0, ID);
end;

end.
